package com.data.util

import java.util.regex.Pattern

/**
 * 数据校验方法
 *
 * @author:HingLo
 * @create 2017-09-13 11:44
 */
object CheckDataUtils {

    /***
     * 邮箱格式校验
     * @param email
     * @return
     */
    fun checkEmail(email: String): Boolean {
        val pattern = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"
        return Pattern.matches(pattern, email)
    }


    /**
     * 判断字符串是空与“”
     *
     * @param str
     * @return
     */
    fun stringUtils(vararg str: String): Boolean = str.none {
        "" == it.trim()
    }

    /**
     * 只能包含，数字，字符，下划线，与中划线
     *
     * @param str
     * @return
     */
    fun stringUtilsID(vararg str: String): Boolean {
        val pattern = "^[A-Za-z0-9_-]+$"
        return str.none { !Pattern.matches(pattern, it) }


    }

    /**
     * .
     * 检测后缀是是否是一个图片格式
     *
     * @param icon
     * @return
     */
    fun iconUtils(icon: String): Boolean {
        val s = arrayOf(".PNG", ".JPG", ".GIF", ".JPEG")
        if (stringUtils(icon)) {
            val icon = icon.toUpperCase()
            s.filter { icon == it }.forEach { return true }
            s.filter({ it -> icon == it }).forEach { return true }
        }
        return false
    }

    /**
     * 视频格式检测
     *
     * @param icon
     * @return
     */
    fun videoUtils(icon: String): Boolean {
        val s = arrayOf(".SWF", ".AVI", ".MP4", ".MRVB")
        val icon = icon.toUpperCase()
        return s.contains(icon)
    }


}
